package com.ruoyi.common.enums;

import lombok.Getter;

import java.util.function.Function;

/**
 * 敏感字段隐藏输出
 */
@Getter
public enum SecretStrategy {

    /**
     * 用户名脱敏
     */
    USERNAME(str -> str.replaceAll("(\\S)\\S(\\S*)", "$1*$2")),

    /**
     * 身份证脱敏
     */
    ID_CARD(str -> str.replaceAll("(\\d{3})\\d{12}(\\w{3})", "$1************$2")),

    /**
     * 手机号脱敏
     */
    PHONE(str -> str.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2")),

    /**
     * 地址脱敏
     */
    ADDRESS(str -> str.replaceAll("(\\S{3})\\S{2}(\\S*)\\S{2}", "$1****$2****")),

    /**
     * 地址脱敏
     */
    PLATE_NO(str -> str.replaceAll("(\\d{3})\\d{3}(\\w{2})", "$1***$2"));

    private final Function<String, String> desensitizer;

    SecretStrategy(Function<String, String> desensitizer){
        this.desensitizer = desensitizer;
    }

}
